package com.Jancode.leetcode;

import com.Jancode.leetcode.util.Node;
import java.util.List;
import java.util.LinkedList;

public class NTreePostorderTraversal {
    class Solution {
        List<Integer> postorder = new LinkedList<>();
        public List<Integer> postorder(Node root) {
            dfs(root);
            return postorder;
        }

        private void dfs(Node root) {
            if(root == null) return;

            for(Node child : root.children) {
                dfs(child);
            }

            // post order - after the subtrees have dealed with then turn to this node
            postorder.add(root.val);
        }
    }
}
